import 'package:built_collection/built_collection.dart';
import 'package:mobile_app.core/core/domain/entities/learning_content/lexical_item/lexical_item.dart';
import 'package:mobile_app.home.core/core/domain/helpers/is_lexical_item_repeatable/helper.dart';

abstract class GetRepeatableLexicalItems {
  BuiltList<LexicalItem> call({
    required BuiltMap<String, LexicalItem> lexicalItemMap,
  });
}

class GetRepeatableLexicalItemsImpl implements GetRepeatableLexicalItems {
  const GetRepeatableLexicalItemsImpl({
    required IsLexicalItemRepeatable isLexicalItemRepeatable,
  }) : _isLexicalItemRepeatable = isLexicalItemRepeatable;

  final IsLexicalItemRepeatable _isLexicalItemRepeatable;

  @override
  BuiltList<LexicalItem> call({
    required BuiltMap<String, LexicalItem> lexicalItemMap,
  }) {
    final repeatableLexicalItems = lexicalItemMap.values.where((lexicalItem) {
      return _isLexicalItemRepeatable(
        lexicalItem: lexicalItem,
      );
    }).toBuiltList();

    return repeatableLexicalItems;
  }
}
